home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / tmempgpkey.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.3 KB  |  73 lines

  1. //    TMemPGPkey.cp - In Memory PGP Key Object  
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinnie Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TMemPGPkey.h"
  18. #include "TPGPException.h"
  19.  
  20. // ---------------------------------------------------------------------------
  21. TMemPGPkey::~TMemPGPkey()
  22. // ---------------------------------------------------------------------------
  23. // 
  24. {
  25.     if(PGPKeySetRefIsValid (fKeySet)) PGPFreeKeySet(fKeySet);
  26. }
  27.  
  28. // ---------------------------------------------------------------------------
  29. void    TMemPGPkey::Initialize(void* buf, PGPSize bufSize )
  30. // ---------------------------------------------------------------------------
  31. // 
  32. {
  33.     PGPKeySetRef    newKeySet         = NULL;
  34.     PGPUInt32         numKeys;
  35.     PGPKeyListRef    theKeyListRef     = kInvalidPGPKeyListRef;
  36.     PGPKeyIterRef    theIterator     = kInvalidPGPKeyIterRef;
  37.     PGPKeyRef        aKey             = kInvalidPGPKeyRef;
  38.     PGPError         err;
  39.  
  40. //DebugStr("\pTMemPGPkey::Initialize");
  41.  
  42.     if(PGPKeySetRefIsValid (fKeySet)) PGPFreeKeySet(fKeySet);
  43.      
  44.     ThrowIfPGPErr ( PGPImportKeySet(fgContext, &newKeySet, 
  45.                          PGPOInputBuffer( fgContext, buf, bufSize ),
  46.                         PGPOLastOption( fgContext) ));
  47.  
  48.       ThrowIfPGPErr( PGPCountKeys(newKeySet, &numKeys));
  49.      if(numKeys > 0) 
  50.     {
  51.         Boolean canSign;
  52.  
  53.         ThrowIfPGPErr( PGPOrderKeySet(newKeySet,kPGPAnyOrdering, &theKeyListRef));
  54.         ThrowIfPGPErr( PGPNewKeyIter( theKeyListRef, &theIterator ));
  55.         
  56.         while(IsntPGPError (PGPKeyIterNext( theIterator, &aKey )))
  57.         {
  58. //            ThrowIfPGPErr( PGPGetKeyBoolean (aKey, kPGPKeyPropCanSign,  &canSign));
  59. //            if(canSign)
  60.                 {
  61.                     fKeySet = newKeySet;
  62.                     TPGPkey::Initialize(aKey);
  63.                     newKeySet = kInvalidPGPKeySetRef;
  64.                     break;
  65.                 }
  66.         }
  67.  
  68.     }
  69.     PGPFreeKeyIter(theIterator );
  70.     PGPFreeKeyList(theKeyListRef );
  71.     if(PGPKeySetRefIsValid (newKeySet)) PGPFreeKeySet(newKeySet);
  72.  }
  73.